package com.hainatong.shiphelper.mainhome.adapter;

import org.jetbrains.annotations.NotNull;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder;
import com.hainatong.shiphelper.R;
import com.hainatong.shiphelper.databinding.ItemExamineProcessStepBinding;
import com.hainatong.shiphelper.mainhome.entity.ExamineStepBean;
import com.hainatong.shiphelper.widget.SpannableBuilder;

import android.view.View;

public class ExamineStepAdapter extends BaseQuickAdapter<ExamineStepBean, BaseDataBindingHolder<ItemExamineProcessStepBinding>>
{
    public ExamineStepAdapter()
    {
        super(R.layout.item_examine_process_step);
    }

    @Override
    protected void convert(@NotNull BaseDataBindingHolder<ItemExamineProcessStepBinding> bindingHolder, ExamineStepBean stepBean)
    {
        ItemExamineProcessStepBinding binding = bindingHolder.getDataBinding();
        if( binding != null )
        {

            binding.tvTime.setText( stepBean.getActiveTime() );

            SpannableBuilder  builder = SpannableBuilder.create(getContext());


            if( stepBean.getStatus() == ExamineStepBean.StepStatus.START )
            {
                binding.startLine.setVisibility( View.GONE );
                binding.endLine.setVisibility( View.VISIBLE );

                binding.ivSetpStart.setImageResource(R.mipmap.ic_label_time);
                binding.ivSetpStart.setVisibility(View.VISIBLE);
                binding.ivSetpPoint.setVisibility(View.GONE);

                builder.append( stepBean.getStepName() , R.dimen.sp_16 , R.color.text_color );
                binding.tvStepTitle.setVisibility( View.VISIBLE );
                binding.tvSubTitle.setVisibility( View.VISIBLE );

                binding.tvStepTitle.setText( builder.build() );
                binding.tvSubTitle.setText( stepBean.getSubName() );
            }
            else if ( stepBean.getStatus() == ExamineStepBean.StepStatus.ACTIVE )
            {

                binding.startLine.setVisibility( View.VISIBLE );
                binding.endLine.setVisibility( View.VISIBLE );

                binding.ivSetpStart.setVisibility(View.GONE);
                binding.ivSetpPoint.setVisibility(View.VISIBLE);

                builder.append( stepBean.getStepName() , R.dimen.sp_16 , R.color.text_color );
                builder.append( stepBean.getSubName() , R.dimen.sp_16 , R.color.red);

                binding.tvStepTitle.setVisibility( View.VISIBLE );
                binding.tvSubTitle.setVisibility( View.GONE );

                binding.tvStepTitle.setText( builder.build() );
            }
            else if ( stepBean.getStatus() == ExamineStepBean.StepStatus.END)
            {
                binding.startLine.setVisibility( View.VISIBLE );
                binding.endLine.setVisibility( View.GONE );

                binding.ivSetpStart.setVisibility(View.GONE);
                binding.ivSetpPoint.setVisibility(View.VISIBLE);

                builder.append( stepBean.getStepName() , R.dimen.sp_14 , R.color.text_color );
                builder.append( stepBean.getSubName() , R.dimen.sp_14 , R.color.red);

                binding.tvStepTitle.setVisibility( View.VISIBLE );
                binding.tvSubTitle.setVisibility( View.GONE );

                binding.tvStepTitle.setText( builder.build() );
            }
        }
    }
}
